package com.example.demospringboot.controller.depcontroller;


import com.example.demospringboot.annotations.ApiOperationSince;
import com.example.demospringboot.annotations.VersionApi;
import com.example.demospringboot.domains.Department;
import com.example.demospringboot.domains.Employee;
import com.example.demospringboot.mapper.DepartmentMapper;
import com.example.demospringboot.mapper.EmployeeMapper;
import com.google.gson.JsonObject;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    private static Logger logger = LoggerFactory.getLogger(DepartmentController.class);

    @Autowired
    DepartmentMapper deptMapper;

	@Autowired
    EmployeeMapper empMapper;

    @GetMapping("/dept/{deptCode}")
    public Department getDepartmentByCode(@PathVariable String deptCode){
        Department dept = deptMapper.getDepartmentByDeptCode(deptCode);
        return dept;
    }


    @ApiOperationSince(value = "1.1", description = "Release 1.1")
    @GetMapping("/{deptCode}")
    public List<Employee> getEmployeeByDeptCode(@PathVariable String deptCode){
        return empMapper.getEmployeeByDeptCode(deptCode);
    }

   // @ApiOperationSince(value = "1.0", description = "Release 1.0")
    @ApiOperation(value = "自定义参数查询部门相关信息3")
    @RequestMapping(value="/cusSearchDep3",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public JsonObject cutSearchDep3(
            @VersionApi int version,
            @RequestBody JsonObject jsonObject){
        logger.info("begin custom search 3 " + jsonObject.toString());
        JsonObject jsonObject1 = new JsonObject();
        jsonObject1.addProperty("aa","test");
        String strTmp = "aaaa";
        logger.info("stTmp is "  + strTmp);
        return jsonObject1;
    }
}
